package com.cw.jeeyt.service.converter.security;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.service.bo.security.SecurityRoleResourceBo;
import com.cw.jeeyt.dao.model.security.SecurityRoleResourceDo;
import com.cw.lang.common.utils.CollectionUtil;

/**
 * 角色资源信息转换类
 *
 * @author chenw
 * @date 2019-03-10 13:01:34
 */
public class SecurityRoleResourceConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static SecurityRoleResourceBo do2Bo(SecurityRoleResourceDo model) {
        if (model == null) {
            return null;
        }
        SecurityRoleResourceBo bo = new SecurityRoleResourceBo();
        bo.setId(model.getId());
        bo.setRoleName(model.getRoleName());
        bo.setRoleComment(model.getRoleComment());
        bo.setResName(model.getResName());
        bo.setRoleId(model.getRoleId());
        bo.setResId(model.getResId());
        bo.setResUrl(model.getResUrl());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static SecurityRoleResourceDo bo2Do(SecurityRoleResourceBo bo) {
        if (bo == null) {
            return null;
        }
        SecurityRoleResourceDo model = new SecurityRoleResourceDo();
        model.setId(bo.getId());
        model.setRoleName(bo.getRoleName());
        model.setResName(bo.getResName());
        model.setRoleComment(bo.getRoleComment());
        model.setRoleId(bo.getRoleId());
        model.setResId(bo.getResId());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<SecurityRoleResourceBo> doList2BoList(List<SecurityRoleResourceDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), SecurityRoleResourceConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<SecurityRoleResourceDo> boList2DoList(List<SecurityRoleResourceBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), SecurityRoleResourceConverter::bo2Do));
    }
}
